package assets_withdraw

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type WithdrawLockListPageLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// c端财务管理页面--提现锁定查询
func NewWithdrawLockListPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WithdrawLockListPageLogic {
	return &WithdrawLockListPageLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *WithdrawLockListPageLogic) WithdrawLockListPage(req *types.WithdrawLockListPageReq) (resp *types.WithdrawLockListPageRes, err error) {
	// todo: add your logic here and delete this line
	rpc_req := &rpc.WithdrawLockListPageReq{
		UserId:    req.UserId,
		Type:      req.Type,
		MixAmount: req.MinAmount,
		MaxAmount: req.MaxAmount,
		StartTm:   req.StartTm,
		EndTm:     req.EndTm,
		Page: &rpc.Page{
			Page:      req.Page.Page,
			PageSize:  req.Page.PageSize,
			SortOrder: req.Page.SortOrder,
		},
	}

	// 发送请求
	rpc_resp, err := l.svcCtx.AssetsRpc.PayWithdraw.WithdrawLockListPage(l.ctx, rpc_req)
	if err != nil {
		return nil, err
	}

	// 处理请求返回的结果
	// 解析、组合数据
	resp = &types.WithdrawLockListPageRes{}
	if rpc_resp.Data != nil {
		resp.Total = rpc_resp.Page.Total
		for i, _ := range rpc_resp.Data {
			d := types.WithDraw{}
			copier.Copy(&d, rpc_resp.Data[i])
			resp.Data = append(resp.Data, d)

		}

	}
	return
}
